﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace ValueProviderTest.App_Start
{
    public class CustomValueProviderProviderAttribute:AuthorizeAttribute
    {
        public bool IsRequire { get; set; }
        public CustomValueProviderProviderAttribute():this(false)
        {

        }
        public CustomValueProviderProviderAttribute(bool _IsRequire)
        {
            this.IsRequire = _IsRequire;
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {

            if (IsRequire)
            {
                filterContext.Controller.ValueProvider =new CustomValueProviderFactory().GetValueProvider(filterContext.Controller.ControllerContext);
            }
            else
            {
                filterContext.Controller.ValueProvider = MyValueProviderFactoryCollection.Factories.GetValueProvider(filterContext.Controller.ControllerContext);
            }
            //base.OnAuthorization(filterContext);
        }
    }
}